package lrg10002.exostention.core;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

import lrg10002.exostention.element.ItemElement;
import net.minecraft.item.Item;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderState.ModState;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = "lrg10002_exostention", name = "Exostention", version = "EXO_0.01")
@NetworkMod(clientSideRequired = true, serverSideRequired = true)
public class ExostentionMod {

	@Instance("lrg10002_exostention")
	public static ExostentionMod instance;

	@SidedProxy(clientSide = "lrg10002.exostention.core.EClientProxy", serverSide = "lrg10002.exostention.core.ECommonProxy")
	public static ECommonProxy commonProxy;

	public Item elementItem = new ItemElement(7251).setItemName("exostention_elementItem");

	// use item ids from 7251 to 8255

	@PreInit
	public void preInit(FMLPreInitializationEvent event) {
		File folder = event.getModConfigurationDirectory();
		if (!folder.exists()) {
			folder.mkdir();
		}
		File imconf = new File(folder, "makeups.csv");
		if (!imconf.exists()) {
			// load from jar
		}

		try {
			LineNumberReader lnr = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(imconf))));
		} catch (Exception e) {
			System.out.println("Failed to load config. Disabling Exostention.");
			if (Loader.instance().activeModContainer().getModId().equals("lrg10002_exostention")) {
				Loader.instance().activeModContainer().setEnabledState(false);
			}
		}

	}

	@Init
	public void Init(FMLInitializationEvent event) {
		((ItemElement) elementItem).initNames();
	}
}
